package PhotoVoltaic.UI;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
//the main frame
public class Front_end {
	//main
	 JFrame UI;
	//equipment
	 JLabel equip_name_l, status_l;
	//combiner
	 JLabel inVolt_l, outVolt_l, outPower_l;
	//Inverter
	 JLabel tol_Volt, tol_Cur;
	//conbiner TextField
	 JTextField inVolt_t, outVolt_t, outPower_t;
	//inverter Textfield
	 JTextField tol_Volt_t, tol_Cur_t, name_t, status_t;
	//panel to help the placement
	 JPanel panel0, panel1, panel2, panel3;
	//button
	 JButton add_b, delete_b, query_b;
	//raduibutton
	 JRadioButton combiner_b, inverter_b;
	 ButtonGroup equipgroup;
	 JPanel b_panel;
	//Table
	 DefaultTableModel Equip_Table_model;
	 JTable Equip_Table;
	 JScrollPane ScrollPane;
	 Vector vdata;
	 Vector vcoldata;
	//constructor
	Front_end(String title) {
		//define the UI
		UI = new JFrame(title);
		UI.setSize(800, 500);
		//combiner label
		equip_name_l = new JLabel("设备名称");
		inVolt_l = new JLabel("输入电压");
		outVolt_l = new JLabel("输出电压");
		outPower_l = new JLabel("输出功率");
		status_l = new JLabel("设备状态");
		//inverter label
		tol_Volt = new JLabel("总电压");
		tol_Cur = new JLabel("总电流");
		//main text
		name_t = new JTextField(15);
		status_t = new JTextField(15);
		//combiner Text
		inVolt_t = new JTextField(15);
		outVolt_t = new JTextField(15);
		outPower_t = new JTextField(15);
		//inverter Text
		tol_Volt_t = new JTextField(15);
		 tol_Cur_t = new JTextField(15);
		//function button
		add_b = new JButton("添加");
		delete_b = new JButton("删除");
		query_b = new JButton("查询");
		//radiobutton
		combiner_b = new JRadioButton("汇流箱");
		inverter_b = new JRadioButton("逆变器");
		equipgroup = new ButtonGroup();
		equipgroup.add(combiner_b);
		equipgroup.add(inverter_b);
		b_panel = new JPanel();
		b_panel.add(combiner_b);
		b_panel.add(inverter_b);
		//add the name to the panel0
		panel0 = new JPanel();
		panel0.add(equip_name_l);
		panel0.add(name_t);
		panel0.add(status_l);
		panel0.add(status_t);
		//add combiner data to the panel1
		panel1 = new JPanel();
		panel2 = new JPanel();
		panel3 = new JPanel();
		panel1.add(inVolt_l);
		panel1.add(inVolt_t);
		panel1.add(outVolt_l);
		panel1.add(outVolt_t);
		panel1.add(outPower_l);
		panel1.add(outPower_t);
		//add inverter data to the panel2
		panel2.add(tol_Volt);
		panel2.add(tol_Volt_t);
		panel2.add(tol_Cur);
		panel2.add(tol_Cur_t);
		//add the button to the panel3
		panel3.add(add_b);
		panel3.add(delete_b);
		panel3.add(query_b);
		//Add all the components to the frame
		UI.add(b_panel);
		UI.add(panel0);
		UI.add(panel1);
		UI.add(panel2);
		UI.add(panel3);

		//add the table
		vdata = new Vector(); //note! remenber to initialize the vector
		vcoldata = new Vector();

		Equip_Table_model = new DefaultTableModel(vdata, vcoldata);
		Equip_Table = new JTable(Equip_Table_model);
		ScrollPane = new JScrollPane(Equip_Table);
		UI.add(ScrollPane);

		UI.setLayout(new FlowLayout());
		UI.setVisible(true);
		UI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
